One field of our struct is Guid type. How to generate a valid value for it?
If you are using this in the Reflection C#, you can get the guid from the property attribute as follows
var propertyAttributes= property.GetCustomAttributes();
foreach(var attribute in propertyAttributes)
{
var myguid= Guid.Parse(attribute.Id.ToString());
}
Guid id = Guid.NewGuid();
Guid.NewGuid() will create one
To makes an "empty" all-0 guid like 00000000-0000-0000-0000-000000000000
.
var makeAllZeroGuID = new System.Guid();
or
var makeAllZeroGuID = System.Guid.Empty;
To makes an actual guid with a unique value, what you probably want.
var uniqueGuID = System.Guid.NewGuid();
If you want to create a "desired" Guid you can do
var tempGuid = Guid.Parse("<guidValue>");
where <guidValue>
would be something like 1A3B944E-3632-467B-A53A-206305310BAE
.
There are two ways
var guid = Guid.NewGuid();
or
var guid = Guid.NewGuid().ToString();
both use the Guid class, the first creates a Guid Object, the second a Guid string.